package Controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.AppliedDataDTO;
import model.UserDTO;
import bizlogic.UserManager;
import bizlogic.UserManager1;

/**
 * Servlet implementation class for Servlet: ProcessServlet
 * --Hnin Phyo--
 */
 public class processservlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public processservlet() {
		super();
	}   	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}  	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}   	  	   
	private void processRequest(HttpServletRequest request, HttpServletResponse response) {
		
		UserDTO us =(UserDTO)request.getSession().getAttribute("user");
		String id = us.getId().toString();
		
		UserManager1 um = new UserManager1();
		ArrayList<AppliedDataDTO> data = um.findAllAppliedUser(id);
		request.setAttribute("Datas", data);
		RequestDispatcher rd = request.getRequestDispatcher("AppliedList.jsp");
		try {
			rd.forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}